/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication1;

import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.widgets.Canvas;

/**
 *
 * @author Oren
 */
public class ArmAddition implements Robot{
    private Robot robot;
    private boolean loaded;
    private Box robotbox;
    private String Type = " Robot with arm of ";
    private boolean assign = false;


    public ArmAddition(Robot rbt)
    {
        this.robot = rbt;
        loaded = false;
        robot.setType(Type);
    }

    

     public void setStartingPosition(Position p) {
        robot.setStartingPosition(p);

    }
     public boolean pickupBox(Box b)
     {
         // check if the arm isn't avaliable
         if (loaded == true )
             return false;
         // check the box postion
         if (b.getPosition().x == this.getCurrentPosition().x)
             if (b.getPosition().y == this.getCurrentPosition().y)
                if (this.loaded == false)
                    if (b.getVisable() == true)
                    {
                         b.setNonVisable();
                         this.loaded = true;
                         robotbox = b;
                    }
         return loaded;
         
     }

    public void move(int speed, int heading) {
        robot.move(speed, heading);

    }

    public void stop() {
        robot.stop();
    }

    public Position getCurrentPosition(){
        return robot.getCurrentPosition();
    }

    public void act() {
       robot.act();
    }

    public String getName() {
        return robot.getName();
    }

    public void setName(String name) {
        robot.setName(name);
    }

    public int getDistance() {
        return robot.getDistance();
    }

    public int compareTo(Robot arg0) {
        return robot.compareTo(arg0);
    }

    public void setPre(Position temp) {
        robot.setPre(temp);
    }

    public Position getStartPosition() {
        return robot.getStartPosition();
    }

    public int getSpeedLimit() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public int getHeadingLimit() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public int getHeading() {
        return robot.getHeading();
    }

    public boolean putdownBox()
    {
        // check that the robot has a box
        if (loaded == true)
        {
            // check that no box is in this postioin - NOT SUPORRTED YET

            // update the arm to empty mode
            loaded = false;

            // update box location
            robotbox.setPosition(this.getCurrentPosition());

            // change box to visable
            robotbox.setVisable();
            return true;
        }
        return false;   

    }
    public String getType()
    {
        String temp = robot.getType();
        String temp2 = null;
        String words[] = temp.split(" ");

        if (words[0].equalsIgnoreCase("smart"))
            temp2 = (words[1]+this.Type+words[0]+" "+words[1]+" "+words[2]+" "+words[3]);
        else
            temp2 = (words[0]+this.Type+words[1]);
        return temp2;

    }
  public void setAssign()
    {
        assign = true;
    }

  public boolean getAssign()
  {
      return assign;
  }

  public void paint(PaintEvent e){
	// using the decorator pattern for adding the arm drawing
	Canvas c=(Canvas)e.widget;	// get the canvas
	int maxX = c.getSize().x;	// max size
	int maxY = c.getSize().y;
	int mx=maxX/2,my=maxY/2;	// mid point as (0,0)
	int myX = mx+robot.getCurrentPosition().x;	// set the current position
	int myY=  my-robot.getCurrentPosition().y;	// set the current position

        
	
        robot.paint(e);
        

        // drawing the lower line :
        e.gc.drawLine(myX-7, myY+7 ,myX+7, myY+7);
        // drawing the right line :
        e.gc.drawLine(myX+7, myY+7,myX+7, myY-7);
        // drawing the left line :
        e.gc.drawLine(myX-7, myY+7, myX-7, myY-7);

        // add the BOX (if loaded)

        if (loaded)
        {
        e.gc.drawLine(myX-7, myY-7,myX+7, myY-7 );
        e.gc.drawString("B", myX-2, myY-6);
        e.gc.drawString(robotbox.getName(),myX+13, myY+26,true);
        }
}

    public void setType(String type) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

 


}
